<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="亚马逊平台订单id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amzOrderId">
              <a-input v-model="model.amzOrderId" placeholder="请输入亚马逊平台订单id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buyerName">
              <a-input v-model="model.buyerName" placeholder="请输入买家姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家所属国家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buyerCountry">
              <a-input v-model="model.buyerCountry" placeholder="请输入买家所属国家"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buyerMail">
              <a-input v-model="model.buyerMail" placeholder="请输入买家邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家税务信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buyerTaxInfo">
              <a-input v-model="model.buyerTaxInfo" placeholder="请输入买家税务信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverName">
              <a-input v-model="model.receiverName" placeholder="请输入收件人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverPhone">
              <a-input v-model="model.receiverPhone" placeholder="请输入收件人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverCompany">
              <a-input v-model="model.receiverCompany" placeholder="请输入收件人公司"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人邮编" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverZipCode">
              <a-input v-model="model.receiverZipCode" placeholder="请输入收件人邮编"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人国家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverCountry">
              <a-input v-model="model.receiverCountry" placeholder="请输入收件人国家"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人州/地区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverRegion">
              <a-input v-model="model.receiverRegion" placeholder="请输入收件人州/地区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverCity">
              <a-input v-model="model.receiverCity" placeholder="请输入收件人城市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件地址段1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverAddress1">
              <a-input v-model="model.receiverAddress1" placeholder="请输入收件地址段1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件地址段2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverAddress2">
              <a-input v-model="model.receiverAddress2" placeholder="请输入收件地址段2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件地址段3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverAddress3">
              <a-input v-model="model.receiverAddress3" placeholder="请输入收件地址段3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人街道名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="streetName">
              <a-input v-model="model.streetName" placeholder="请输入收件人街道名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="街道号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="streetNumber">
              <a-input v-model="model.streetNumber" placeholder="请输入街道号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="补充单元号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="complementNumber">
              <a-input v-model="model.complementNumber" placeholder="请输入补充单元号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="社区/邻里" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="neighborhood">
              <a-input v-model="model.neighborhood" placeholder="请输入社区/邻里"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AmzOrderBuyerInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/amzOrderBuyerInfo/add",
          edit: "/order/amzOrderBuyerInfo/edit",
          queryById: "/order/amzOrderBuyerInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>